<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class type extends MY_Controller {
	function __construct(){
		parent::__construct();
	}

	function admin_index(){	
		if(!$this->ion_auth->in_group("admin")){
			show_404();
		}
	  $wheretype['order'] = "id ASC";
		$type = $this->typeModel->get($wheretype);
		$this->_assign('types',$type);
		$this->_fetch('admin_index');
	}

	function admin_add($id=""){
		if(!$this->ion_auth->in_group("admin")){
			show_404();
		}
		if(!empty($id)){
			$reslut = $this->typeModel->get($id);
			$this->_assign('type',$reslut);
			$this->_fetch('admin_add');
		}else{
			$posts=$this->input->post();
			if(!empty($posts["submit"]) AND !empty($posts["name"])){
				//$posts['order'] = 0;
				$this->typeModel->add($posts);

				//Delete cache
				$this->cache->delete_folder("category");
				$this->cache->delete("menu_widget_html");

				redirect('admin/type');
			}else{
				$this->_fetch('admin_add');
			}
		}
	}

	function admin_delete($id=""){
		if(!$this->ion_auth->in_group("admin")){
			show_404();
		}
		//Delete cache
		$this->cache->delete_folder("category");
		$this->cache->delete("menu_widget_html");
	 	$this->db->delete('ci_type',array('typ_id'=>$id));
	 	redirect('admin/type');
	}


}